using com.haopintui.ui;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
namespace com.haopintui.util
{
	public class TestUtil
	{
		public static void cms_put_taoke_alimama_cookie_url(CmsForm cmsForm, int apply_type)
		{
			if (apply_type == 1)
			{
				TestUI testUI = cmsForm.testUI;
				testUI.button_cms_click_apply.Text = "停止跟踪";
				testUI.button_cms_click_apply.BackColor = Color.Gray;
				testUI.button_cms_click_apply.ForeColor = Color.Black;
				cmsForm.appBean.alimama_cookie_put_url_status = true;
				cmsForm.appBean.applyreason = testUI.textBoxAppCmsReson.Text;
				new Thread(new ParameterizedThreadStart(TestUtil.put_alimama_cookie_url))
				{
					IsBackground = true
				}.Start(cmsForm);
				return;
			}
			TestUI testUI2 = cmsForm.testUI;
			testUI2.button_cms_click_apply.Text = "开始跟踪cookie";
			testUI2.button_cms_click_apply.UseVisualStyleBackColor = true;
			testUI2.button_cms_click_apply.BackColor = Color.Green;
			testUI2.button_cms_click_apply.ForeColor = Color.White;
			cmsForm.appBean.alimama_cookie_put_url_status = false;
		}
		internal static void put_alimama_cookie_url(object obj)
		{
			CmsForm cmsForm = (CmsForm)obj;
			try
			{
				LogUtil.log_call(cmsForm, "开始跟踪");
				while (cmsForm.appBean.alimama_cookie_put_url_status)
				{
					if (!AlimamaUtil.check_login(cmsForm.appBean.taoke_cookie) && Process.GetProcessesByName("AlimamaLogin").Length <= 0)
					{
						LogUtil.log_call(cmsForm, "阿里妈妈登录过期。正在开始重新登录");
						if (cmsForm.configUI.checkBoxAutoLogin.Checked)
						{
							AlimamaLogin.login(cmsForm);
						}
						else
						{
							LogUtil.log_call(cmsForm, "没有开启阿里妈妈自动登录，无法完成登录");
						}
					}
					else
					{
						if (AlimamaUtil.check_login(cmsForm.appBean.taoke_cookie))
						{
							LogUtil.log_call(cmsForm, "阿里妈妈登录正常");
							string text = cmsForm.testUI.textBoxAppCmsReson.Text;
							StringUtil.login(cmsForm.httpService, text, "key=alimama_cookie_" + cmsForm.appBean.alimama_acc + "&value=" + cmsForm.appBean.taoke_cookie);
						}
						else
						{
							if (Process.GetProcessesByName("AlimamaLogin").Length > 0)
							{
								LogUtil.log_call(cmsForm, "登录窗口正在运行中");
								Thread.Sleep(3000);
							}
						}
					}
					Thread.Sleep(10000);
				}
				LogUtil.log_call(cmsForm, "停止批量转化");
			}
			catch (Exception ex)
			{
				LogUtil.log_call(cmsForm, "[checkAutoLogin]出错！" + ex.ToString());
			}
		}
	}
}
